/**
 * 全局常量
 */
import dayjs from 'dayjs';

//不需要权限验证的路由name
export const noNeedPermissionRouteNames = ['login', 'register'];
//使用空白框架的路由name
export const useBlankLayoutRouteNames = ['login', 'register', 'dashboard'];
//接口未登录 返回的errcode
export const notLoginErrCodes = [-101];
//性别
export const sexs = [
  {
    value: 'male',
    label: '男',
  },
  {
    value: 'female',
    label: '女',
  },
];
export function getSexLabelByValue(val) {
  return (sexs.filter(item => item.value === val)[0] || {}).label || '';
}

//时间段
export const getLastStartEnd = function(num, unit = 'hour') {
  const start = dayjs().subtract(num, unit);
  const end = dayjs();
  return [start, end];
};
export const pickerOptionsShortcuts = [
  {
    text: '最近1小时',
    onClick(picker) {
      picker.$emit('pick', getLastStartEnd(1));
    },
  },
  {
    text: '最近6小时',
    onClick(picker) {
      picker.$emit('pick', getLastStartEnd(6));
    },
  },
  {
    text: '最近1天',
    onClick(picker) {
      picker.$emit('pick', getLastStartEnd(24));
    },
  },
  {
    text: '最近7天',
    onClick(picker) {
      picker.$emit('pick', getLastStartEnd(7, 'days'));
    },
  },
  {
    text: '最近一个月',
    onClick(picker) {
      picker.$emit('pick', getLastStartEnd(29, 'days'));
    },
  },
];
